package com.lson.springboot;

import com.lson.springboot.dao.UserDao;
import com.lson.springboot.entity.User;
import org.apache.ibatis.cursor.Cursor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Iterator;
import java.util.List;
import java.util.Random;

@RestController
public class Demo {
    @Autowired
    UserDao userDao;

    @RequestMapping("/test")
    @Transactional
    public Object test(String a){
        Cursor<User> cursor = userDao.getUsers();
        Iterator<User> iterator = cursor.iterator();
        while (iterator.hasNext()){
            User next = iterator.next();
            System.out.println(next.getName());
        }

        return "users";
    }

    public String transform(String a){
        Random random = new Random();
        if(random.nextBoolean()){
            System.out.println(1/0);
        }
        return a+"success";
    }
}
